/**
 * 分页处理方法集合
 */
var common_splitPage = function () {

    /**
     * 分页链接HTML
     * @param divId
     * @param formId
     * @param totalRow
     * @param pageSize
     * @param pageNumber
     * @param totalPages
     * @param isSelectPage
     * @param isSelectSize
     * @param orderColunm
     * @param orderMode
     * @param currentPageCount
     * @param startRow
     * @param endRow
     * @returns {String}
     */
    var splitPageHtml = function (divId, formId, totalRow, pageSize, pageNumber, totalPages, isSelectPage, isSelectSize) {
        var splitStr = '';

        splitStr += '<ul>';

        if (pageNumber == 1 || totalPages == 0) {
            splitStr += '<li style="text-shadow: #0d8ddb;"><a href="javascript:void(0)">上一页</a></li>';
        } else {
            splitStr += '<li><a href="javascript:common_splitPage.splitPageLink(\'' + divId + '\', \'' + formId + '\', ' + (pageNumber - 1) + ');">上一页</a></li>';
        }

        for (var i = 1; i <= totalPages; i++) {
            if (i == 2 && (pageNumber - 4) > 1) {
                splitStr += '<li><a href="javascript:void(0)" style="width:30px;border-top:1px solid #e7eaec;border-bottom:1px solid #e7eaec;height:30px;diplay:flex;line-height:30px;text-align:center;">...</a></li>';
                i = pageNumber - 4;

            } else if (i == (pageNumber + 4) && (pageNumber + 4) < totalPages) {
                splitStr += '<li style="width:30px;"><a href="javascript:void(0)">...</a></li>';
                i = totalPages - 1;
            } else {
                if (pageNumber == i) {
                    splitStr += '<li style="width:30px ;background:#e7e7e7; color=black;"><a href="javascript:void(0)">' + pageNumber + '</a></li>';
                } else {
                    splitStr += '<li style="width:30px;"><a href="javascript:common_splitPage.splitPageLink(\'' + divId + '\', \'' + formId + '\', ' + i + ');" style="width:300px;">';
                    splitStr += i;
                    splitStr += '</a></li>';
                }
            }
        }

        if (pageNumber == totalPages || totalPages == 0) {
            splitStr += '<li><a href="javascript:void(0)">下一页</a></li>';
        } else {
            var pN = pageNumber + 1;
            splitStr += '<li><a href="javascript:common_splitPage.splitPageLink(\'' + divId + '\', \'' + formId + '\', ' + pN + ');">下一页</a></li>';
        }

        if (isSelectPage == true) {
            splitStr += '&nbsp;&nbsp;<li><select name="pageNumber" onChange="common_splitPage.splitPageLink(\'' + divId + '\', \'' + formId + '\', this.value);" style="width: 120px; height:30px;">';
            for (var i = 1; i <= totalPages; i++) {
                if (i == pageNumber) {
                    splitStr += '<option selected value="' + i + '">跳转到第' + i + '页</option>';
                } else {
                    splitStr += '<option value="' + i + '">跳转到第' + i + '页</option>';
                }
            }
            if (totalPages == 0) {
                splitStr += '<option value="0">无跳转数据</option>';
            }
            splitStr += '</select>';
            splitStr += '<li>&nbsp;&nbsp;';
        } else {
            splitStr += '<input type="hidden" name="pageIndex">';
        }

        if (isSelectSize == true) {
            splitStr += '<li><select name="pageSize" onChange="common_splitPage.splitPageLink(\'' + divId + '\', \'' + formId + '\', 1);" style="width: 100px; height:30px;">';

            var optionStr = '<option value="10">每页' + '10' + '页</option>';
            optionStr += '<option value="20">' + \u6BCF\u9875 + '20' + \u6761 + '</option>';
            optionStr += '<option value="40">' + \u6BCF\u9875 + '40' + \u6761 + '</option>';
            optionStr += '<option value="80">' + \u6BCF\u9875 + '80' + \u6761 + '</option>';
            optionStr += '<option value="100">' + \u6BCF\u9875 + '100' + \u6761 + '</option>';
            optionStr += '<option value="200">' + \u6BCF\u9875 + '200' + \u6761 + '</option>';
            optionStr = optionStr.replace('"' + pageSize + '"', '"' + pageSize + '" selected="selected"');

            splitStr += optionStr;

            splitStr += '</select></li>';
        } else {
            splitStr += '<input type="hidden" name="pageSize">';
        }
        //<li>显示<strong>' + startRow + '至<strong>' + endRow + '</strong>条，
        splitStr += '&nbsp;&nbsp;共<strong>' + totalRow + '</strong>条记录</li>';

        splitStr += '</ul>';

        //splitStr += '<input type="hidden" name="orderColunm" value="' + orderColunm + '"/>';
        //splitStr += '<input type="hidden" name="orderMode" value="' + orderMode + '"/>';

        return splitStr;
    };

    /**
     * 分页链接处理
     * @param divId
     * @param formId
     * @param toPage
     */
    var splitPageLink = function (divId, formId, toPage) {
        $("#" + formId + " select[name=pageIndex],input[name=pageIndex] ").val(toPage);
        if (divId == "manage_content") {
            takeout.ajaxFormMainPanel(formId);
        } else {
            takeout.ajaxFormDiv(divId, formId);
        }
    };

    /**
     * 分页列排序点击事件处理
     * @param divId
     * @param formId
     * @param colunmName

    var orderbyFun = function (divId, formId, colunmName) {
        var orderColunmNode = $("#" + formId + " input[name=orderColunm]");
        var orderColunm = orderColunmNode.val();

        var orderModeNode = $("#" + formId + " input[name=orderMode]");
        var orderMode = orderModeNode.val();

        if (colunmName == orderColunm) {
            if (orderMode == "") {
                orderModeNode.val("asc");
            } else if (orderMode == "asc") {
                orderModeNode.val("desc");
            } else if (orderMode == "desc") {
                orderModeNode.val("");
            }
        } else {
            orderColunmNode.val(colunmName);
            orderModeNode.val("asc");
        }

        //alert(orderColunmNode.val()+"--"+orderModeNode.val());

        if (divId == "manage_content") {
            takeout.ajaxFormMainPanel(formId);
        } else {
            common_ajax.ajaxFormDiv(divId, formId);
        }
    };*/

    return {
        splitPage: splitPageHtml,
        splitPageLink: splitPageLink
        //orderbyFun: orderbyFun
    };

}();
